﻿@using GoodMan.Infrastructure.Entities.Entity;
@{
    ViewBag.Title = "返佣报表制作";
    Layout = "~/Areas/WorkSpace/Views/Shared/_OfficerTemplete.cshtml";

    List<Dormitory> data = ViewBag.LastMonthOrders;

    string datemonth = DateTime.Now.AddMonths(-1).ToString("yyyy年MM月");
    string year = DateTime.Now.AddMonths(-1).Year.ToString();
    string month = DateTime.Now.AddMonths(-1).Month.ToString();
}
@section head{
    
    <script type="text/javascript">
        var r = /-?\d*\.?\d*/;
        function changebonus(id,price) {
           
            var obj = $("input[name='bonus" + id + "']");
            var value = obj.val();
           
            if (!r.test(value*1)) {
                $("input[name='bonus" + id + "']").val("");
                value = 0;
            }
            if (value == "-") {
                value = 0;
            }
            var totalMoney = price * 1 + value * 1;
             
            $("span[id='lastMoney" + id + "']").html(fffmoney(totalMoney, 2));
        }

        
       
        function fffmoney(s, n) {
            n = n > 0 && n <= 20 ? n : 2;
            s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
            var l = s.split(".")[0].split("").reverse();
            var r = s.split(".")[1];
            var t = "";
            for (i = 0; i < l.length; i++) {
                t += l[i] + "";
            } 
            return t.split("").reverse().join("") + "." + r;

        }
        
    </script>
}
<div id="content-header">
    <h1>
        返佣报表制作</h1>
</div>
<div id="breadcrumb">
    <a href="index.html" title="Go to Home" class="tip-bottom"><i class="icon-home"></i>
        首页</a> <a href="#" class="tip-bottom">返佣管理</a> <a href="#" class="current">报表制作</a>
</div>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <div class="widget-box">
                <div class="widget-title">
                    <span class="icon"><i class="icon-th"></i></span>
                    <h5>
                        返佣报表制作</h5>
                </div>
                 <form action="/WorkSpace/Officer/SaveUserRebate" method="post" id="productDetailForm"
                    class="form-horizontal">
                <div class="widget-content nopadding">
               
                <table border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td style="width:40%">
                                <div class="control-group">
                                     
                                    <div class="controls">
                                       返佣月份：<span style="color:Red;font-weight:bold">@datemonth</span>
                                       <input type="hidden" name="year" value="@year" /><input type="hidden" name="month" value="@month" />
                                    </div>
                                </div>
                            </td>
                            </tr>
                            <tr>
                            <td>
                    <table class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th width="5%">
                                    楼栋
                                </th>
                                <th width="10%">
                                    姓名
                                </th>
                                 <th width="10%">
                                    处理订单量
                                </th>
                                <th width="10%">
                                    成功订单量
                                </th>
                                <th width="10%">
                                    取消订单量
                                </th>
                                <th width="10%">
                                    成功订单金额
                                </th>
                                 <th width="10%">
                                    返点%
                                </th>
                                <th width="10%">
                                    返点金额
                                </th>
                                 <th width="10%">
                                    调整
                                </th>
                                <th width="10%">
                                    佣金
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                        @{
                            if (data != null && data.Any())
                            {
                                string usernames = "";
                                foreach (var item in data)
                                {
                                    int rowcount = 1;
                                    if (item.RebateReportList != null)
                                    {
                                        rowcount = item.RebateReportList.Count;
                                    }
                                    @:<tr>
                                    <td rowspan="@rowcount" valign="middle">
                                        @item.Name
                                    </td>
                                    if (item.RebateReportList != null && item.RebateReportList.Count > 0)
                                    {


                                        int j = 0;
                                        foreach (var rebate in item.RebateReportList)
                                        {
                                            int dealorders = rebate.SuccessOrders + rebate.CancelOrders;
                                            decimal bonusmoney = Math.Round(rebate.SuccessMoney * rebate.Rebate / 100, 2);
                                            decimal lastmoney = bonusmoney + rebate.Bonus;
                                            usernames = usernames + rebate.UserName + ",";

                                            if (j == 0)
                                            {
                                            <td>
                                                @rebate.user.RealName  <input type="hidden" name="DormitoryId@(rebate.UserName)" value="@item.Id" />
                                            </td>
                                            <td class="center">
                                                @dealorders 
                                            </td>
                                            <td class="center">
                                                @rebate.SuccessOrders <input type="hidden" name="SuccessOrders@(rebate.UserName)" value="@rebate.SuccessOrders" />
                                            </td>
                                            <td class="center">
                                                @rebate.CancelOrders <input type="hidden" name="CancelOrders@(rebate.UserName)" value="@rebate.CancelOrders" />
                                            </td>
                                            <td class="center">
                                                @rebate.SuccessMoney <input type="hidden" name="SuccessMoney@(rebate.UserName)" value="@rebate.SuccessMoney" />
                                            </td>
                                             <td class="center">
                                                @(rebate.Rebate)% <input type="hidden" name="Rebate@(rebate.UserName)" value="@rebate.Rebate" />
                                            </td>
                                            <td class="center">
                                                @bonusmoney
                                            </td>
                                            <td class="center">
                                                <input type="text" name="bonus@(rebate.UserName)" value="@rebate.Bonus" onkeyup="changebonus('@rebate.UserName',@bonusmoney)" style="width: 50px" onkeypress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false"/>
                                            </td>
                                            <td class="center">
                                               <span id="lastMoney@(rebate.UserName)">@lastmoney</span>
                                            </td>
                                            @:</tr>
                                            }
                                            else
                                            {
                                                @:<tr>
                                                 <td>
                                                @rebate.user.RealName  <input type="hidden" name="DormitoryId@(rebate.UserName)" value="@item.Id" />
                                            </td>
                                            <td class="center">
                                                @dealorders
                                            </td>
                                            <td class="center">
                                                @rebate.SuccessOrders <input type="hidden" name="SuccessOrders@(rebate.UserName)" value="@rebate.SuccessOrders" />
                                            </td>
                                            <td class="center">
                                                @rebate.CancelOrders <input type="hidden" name="CancelOrders@(rebate.UserName)" value="@rebate.CancelOrders" />
                                            </td>
                                            <td class="center">
                                                @rebate.SuccessMoney <input type="hidden" name="SuccessMoney@(rebate.UserName)" value="@rebate.SuccessMoney" />
                                            </td>
                                             <td class="center">
                                               @(rebate.Rebate)%<input type="hidden" name="Rebate@(rebate.UserName)" value="@rebate.Rebate" />
                                            </td>
                                            <td class="center">
                                                @bonusmoney
                                            </td>
                                            <td class="center">
                                                <input type="text" name="bonus@(rebate.UserName)"  value="@rebate.Bonus" onkeyup="changebonus('@rebate.UserName',@bonusmoney)" style="width: 50px" onkeypress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false"/>
                                            </td>
                                            <td class="center">
                                               <span id="lastMoney@(rebate.UserName)">@lastmoney</span>
                                            </td>
                                            @:</tr>
                                            }
                                            j++;
                                        }

                                    }
                                    else
                                    {
                                        <td>
                                                
                                            </td>
                                            <td>
                                                
                                            </td>
                                            <td>
                                                
                                            </td>
                                            <td>
                                                
                                            </td>
                                            <td>
                                                
                                            </td>
                                             <td>
                                                
                                            </td>
                                            <td>
                                               
                                            </td>
                                            <td>
                                                
                                            </td>
                                            <td>
                                                
                                            </td>
                                            @:</tr>
                                    }

                                }
                                <input type="hidden" value="@usernames" name="userNames" />
                            }
                        }
                        </tbody>
                    </table>
                    </td></tr>
                    </table>

                    
                </div>
                        <div class="form-actions" style="text-align:right;">
                            <button type="submit" class="btn btn-primary">
                                保存</button>
                        </div>
                        @{
                                         
                            if (ViewBag.Message != null)
                            {
                                if (ViewBag.Message)
                                { 
                        <div class="alert alert-success">
                            <strong>报表保存成功！</strong>
                        </div>
                                                 
                                }
                                else
                                {
                        <div class="alert alert-error">
                            <strong>报表保存失败！</strong>
                        </div>
                                                 
                            }
                        }
                    }
                        </form>
            </div>
             
        </div>
    </div>
</div>
@section tail{
<script type="text/javascript">
    $(function () {
        $('#likRebate').addClass('open');
        $('#likRebate').addClass('active');
    });
</script>
